-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[ConstraintElim] Preserve analyses when IR is unchanged. #128588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ConstraintElim] Preserve analyses when IR is unchanged. #128588
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Andreas Jonson (andjo403) ChangesNoticed that all Analys passes was not preserved for unchanged IR when the test was containing assumes.
Not sure how to/if possible to add a test for this. Full diff: https://github.com/llvm/llvm-project/pull/128588.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 79f6858463d7e..267eb319a5616 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1435,8 +1435,9 @@ static bool checkAndReplaceCondition(
generateReproducer(Cmp, ReproducerModule, ReproducerCondStack, Info, DT);
Constant *ConstantC = ConstantInt::getBool(
CmpInst::makeCmpResultType(Cmp->getType()), IsTrue);
- Cmp->replaceUsesWithIf(ConstantC, [&DT, NumIn, NumOut,
- ContextInst](Use &U) {
+ bool Changed = false;
+ Cmp->replaceUsesWithIf(ConstantC, [&DT, NumIn, NumOut, ContextInst,
+ &Changed](Use &U) {
auto *UserI = getContextInstForUse(U);
auto *DTN = DT.getNode(UserI->getParent());
if (!DTN || DTN->getDFSNumIn() < NumIn || DTN->getDFSNumOut() > NumOut)
@@ -1448,12 +1449,14 @@ static bool checkAndReplaceCondition(
// Conditions in an assume trivially simplify to true. Skip uses
// in assume calls to not destroy the available information.
auto *II = dyn_cast<IntrinsicInst>(U.getUser());
- return !II || II->getIntrinsicID() != Intrinsic::assume;
+ bool ShouldReplace = !II || II->getIntrinsicID() != Intrinsic::assume;
+ Changed |= ShouldReplace;
+ return ShouldReplace;
});
NumCondsRemoved++;
if (Cmp->use_empty())
ToRemove.push_back(Cmp);
- return true;
+ return Changed;
};
if (auto ImpliedCondition =
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to/if possible to add a test for this.
You might be able to use something like
opt -S -passes='require<scalar-evolution>,constraint-elimination' -debug-pass-manager
to check that scalar-evolution is preserved with the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
opt -S -passes='require<scalar-evolution>,constraint-elimination' -debug-pass-manager
to check that scalar-evolution is preserved with the change
Looks like scalar evolution is currently already in the set of the preserved analyses.
Then we should use an analysis that doesn't get preserved even when changes are made. |
cf3be5b
to
ed9c629
Compare
test added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Noticed that all Analys passes was not preserved for unchanged IR when the test was containing assumes.
PreservedAnalyses::all()
is not called for E.g. https://github.com/andjo403/llvm-project/blob/e24bb833b1af521fc2aec997a8b89de795b34449/llvm/test/Transforms/ConstraintElimination/mul.ll#L283-L301Not sure how to/if possible to add a test for this.